package com.XinYun.Library.modules.Login.Servlet;

import com.XinYun.Library.modules.commons.ResponseWrapper.ResponseWrapper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "FindPwdServlet2", value = "/FindPwdServlet2")
public class FindPwdServlet2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader reader = request.getReader();
        String readerLine = reader.readLine();
        JSONObject jsonObject = JSON.parseObject(readerLine);
        String mailcode = jsonObject.getString("mailcode");

        HttpSession session = request.getSession();
        Object emailcode = session.getAttribute("Emailcode");
        if(emailcode == null || !emailcode.toString().equals(mailcode)){
            ResponseWrapper responseWrapper = null;
            responseWrapper = ResponseWrapper.CodeFail();
            String s = JSON.toJSONString(responseWrapper);
            PrintWriter writer = response.getWriter();
            writer.println(s);
            System.out.println(s);
            //request.getRequestDispatcher("repassword2.jsp").forward(request,response);
        }else{
            ResponseWrapper responseWrapper = null;
            responseWrapper = ResponseWrapper.NoData();
            String s = JSON.toJSONString(responseWrapper);
            PrintWriter writer = response.getWriter();
            writer.println(s);
            System.out.println(s);
            //request.getRequestDispatcher("repassword3.jsp").forward(request,response);
        }

    }
}
